﻿#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <chrono>

void bubbleSort(std::vector<int>& a) {
    for (size_t i = 0; i < a.size() - 1; ++i) {
        for (size_t u = 0; u < a.size() - i - 1; ++u) {
            if (a[u] > a[u + 1]) {
                std::swap(a[u], a[u + 1]);
            }
        }
    }
}

int main() {
    std::vector<std::string> files_list = { "m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt" };
    for (const auto& file : files_list) {
        std::ifstream f(file);
        std::vector<int> b;
        int line;
        while (f >> line) {
            b.push_back(line);
        }
        auto time_start = std::chrono::high_resolution_clock::now();
        bubbleSort(b);
        auto time_end = std::chrono::high_resolution_clock::now();
        auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(time_end - time_start);
        int d = duration.count();
        std::string file_name = file.substr(0, file.find('.'));
        std::cout << file_name << " " << d << " milliseconds" << std::endl;
    }
    return 0;
}